package com.woniuxy.microgoodsserver.auctionmag.mapper;

import com.woniuxy.microgoodsserver.bean.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsMapper {


//    //商品通过id查询
//    @Results({
//            @Result(id=true,property = "id",column = "id",javaType = int.class),
//            @Result(property = "goodsName",column = "goods_name",javaType = String.class),
//            @Result(property = "retaiPrice",column = "retai_price",javaType = BigDecimal.class),
//            @Result(property = "upsetPrice",column = "upset_price",javaType = BigDecimal.class),
//            @Result(property = "marketPrice",column = "market_price",javaType = BigDecimal.class),
//            @Result(property = "costPrice",column = "cost_price",javaType = BigDecimal.class),
//            @Result(property = "memberSpecials",column = "member_specials",javaType = BigDecimal.class),
//            @Result(property = "integralPresent",column = "integral_present",javaType = int.class),
//            @Result(property = "mnemonicCode",column = "mnemonic_code",javaType = String.class),
//            @Result(column = "fk_sz_id",property = "mallSettingBean",javaType = MallSettingBean.class,
//                    one = @One(select = "com.woniuxy.microgoodsserver.auctionmag.mapper.MallSettingMapper.mallSettingFindAll",fetchType = FetchType.LAZY)),
//            @Result(column = "fk_lb_id",property = "goodsSortBean",javaType = GoodsSortBean.class,
//                    one = @One(select = "com.woniuxy.microgoodsserver.auctionmag.mapper.GoodsSortMapper.sortFindAll",fetchType = FetchType.LAZY)),
//            @Result(column = "fk_bm_id",property = "goodsNumble",javaType = GoodsNumble.class,
//                    one = @One(select = "com.woniuxy.microgoodsserver.auctionmag.mapper.GoodsNumbleMapper.numbleFindAll",fetchType = FetchType.LAZY)),
//            @Result(column = "fk_pp_id",property = "goodsBrandBean",javaType = GoodsBrandBean.class,
//                    one = @One(select = "com.woniuxy.microgoodsserver.auctionmag.mapper.GoodsBrandMapper.brandFindAll",fetchType = FetchType.LAZY)),
//            @Result(column = "fk_dw_id",property = "goodsUnitBean",javaType = GoodsUnitBean.class,
//                    one = @One(select = "com.woniuxy.microgoodsserver.auctionmag.mapper.GoodsUnitMapper.unitFindAll",fetchType = FetchType.LAZY))
//    })
//    @Select("select id,goods_name,retai_price,upset_price,market_price,cost_price,member_specials," +
//            "integral_present,mnemonic_code,fk_sz_id,fk_lb_id,fk_bm_id,fk_pp_id,fk_dw_id,promo_status" +
//            "from t_goods_nature_info where id = #{id} and del_status=0")
    GoodsBean goodsFindAllById(@Param("id")int id);

    //商品分页查询
    List<GoodsBean> goodsFindAll(@Param("p")PageRequest request, @Param("g")GoodsBean goodsBean);


    //商品增加
    @Options(useGeneratedKeys = true,keyProperty = "g.id")
    @Insert("insert into t_goods_nature_info " +
            "(goods_name," +
            "retai_price,upset_price,market_price,cost_price,member_specials," +
            "integral_present,mnemonic_code," +
            "fk_sz_id,fk_lb_id,fk_bm_id,fk_pp_id,fk_dw_id," +
            "promo_status,buy_status,del_status)" +
            " values(#{g.goodsName},#{g.retaiPrice},#{g.upsetPrice},#{g.marketPrice},#{g.costPrice},#{g.memberSpecials}," +
            "#{g.integralPresent},#{g.mnemonicCode}," +
            "#{g.mallSettingBean.id},#{g.goodsSortBean.id},#{g.goodsNumble.id},#{g.goodsBrandBean.id},#{g.goodsUnitBean.id}," +
            "'0','0','0')")
    int saveGoods(@Param("g") GoodsBean goodsBean);


    //商品修改
    @Update("<script>" +
            "update t_mall_setting_info" +
            "<set>" +
            "<if test='g.goodsName != null'>" +
            " goods_name = #{g.goodsName}," +
            "</if>" +


            "<if test='g.retaiPrice != null'>" +
            " retai_price = #{g.retaiPrice}," +
            "</if>" +
            "<if test='g.upsetPrice != null'>" +
            " upset_price = #{g.upsetPrice}," +
            "</if>" +
            "<if test='g.marketPrice != null'>" +
            " market_price = #{g.marketPrice}," +
            "</if>" +
            "<if test='g.costPrice != null'>" +
            " cost_price = #{g.costPrice}," +
            "</if>" +
            "<if test='g.memberSpecials != null'>" +
            " member_specials = #{g.memberSpecials}," +
            "</if>" +

            "<if test='g.integralPresent != null'>" +
            " integral_present = #{g.integralPresent}," +
            "</if>" +
            "<if test='g.mnemonicCode != null'>" +
            " mnemonic_code = #{g.mnemonicCode}," +
            "</if>" +

            "<if test='g.mallSettingBean.id != null'>" +
            " fk_sz_id = #{g.mallSettingBean.id}," +
            "</if>" +
            "<if test='g.goodsSortBean.id != null'>" +
            " fk_lb_id = #{g.goodsSortBean.id}," +
            "</if>" +
            "<if test='g.goodsNumble.id != null'>" +
            " fk_bm_id = #{g.goodsNumble.id}," +
            "</if>" +
            "<if test='g.goodsBrandBean.id != null'>" +
            " fk_pp_id = #{g.goodsBrandBean.id}," +
            "</if>" +
            "<if test='g.goodsUnitBean.id != null'>" +
            " fk_dw_id = #{g.goodsUnitBean.id}," +
            "</if>" +

            "<if test='g.promoStatus != null'>" +
            " promo_status = #{g.promoStatus}," +
            "</if>" +
            "<if test='g.buyStatus != null'>" +
            " buy_status = #{g.buyStatus}," +
            "</if>" +

            "</set>" +
            "where id = #{g.id}" +
            "</script>")
    int updateGoods(@Param("g") GoodsBean goodsBean);

    //商品删除
    @Update("<script>" +
            "update t_goods_nature_info" +
            "<set>" +
            " del_status = '1'" +
            "</set>" +
            "where id = #{i.id}" +
            "</script>")
    int delGoods(@Param("g") GoodsBean goodsBean);


}
